n = int(input())
g = int(input())
a = []
a.append(g)
for i in range(n-1):
  x,y,z = map(int,input().split())
  if z == 1:
    a.insert(a.index(y)+1,x)
  else:
    a.insert(a.index(y),x)
for i in a:
  print(i,end=' ')